<script setup>
import { useRouter } from 'vue-router'
import { onMounted } from 'vue'

const router = useRouter()
const getcary = () => {
  router.push(`/goods/channel`)
}

defineProps({
  data: {}
})

onMounted(() => {
  const menuBtn = document.querySelector('.menu-icon span')
  const cancelBtn = document.querySelector('.cancel-icon')
  const items = document.querySelector('.nav-items')

  menuBtn.onclick = () => {
    items.classList.add('active')
    menuBtn.classList.add('hide')
    cancelBtn.classList.add('show')
  }

  cancelBtn.onclick = () => {
    items.classList.remove('active')
    menuBtn.classList.remove('hide')
    cancelBtn.classList.remove('show')
    cancelBtn.style.color = '#ff3d00'
  }
})
</script>
<template>
  <div class="header">
    <!-- menu-icon -->
    <div class="menu-icon">
      <span>==</span>
    </div>
    <!-- logo -->
    <div class="logo">
      <span @click="router.push('/goods/mode')">邀奇平台</span>
    </div>
    <!-- 导航 -->
    <div class="nav-items">
      <li v-for="item in data" :key="item.id">
        <span @click="getcary(item.id)">{{ item.name }}</span>
      </li>
    </div>
    <div class="cancel-icon">
      <span>Cancel</span>
    </div>
    <!-- 购物车 -->
    <div class="cart">
      <span class="iconfont icon-cart-full" @click="router.push('/goods/car')">
        购物车
      </span>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.header {
  outline: none;
  box-sizing: border-box;
  font-family: 'Montseerrat', sans-serif;
  background: #171c24;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  height: 70px;
  padding: 0 100px;
}

.header .logo {
  color: #fff;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -1px;
  cursor: pointer;
}

.header .nav-items {
  display: flex;
  flex: 1;
  padding: 0 0 0 40px;
}

.header .nav-items li {
  color: #fff;
  font-size: 18px;
  font-weight: 500;
  list-style: none;
  padding: 0 15px;
  cursor: pointer;
}

.header .nav-items li:hover {
  color: #ff3d00;
}
.header .menu-icon,
.header .cancel-icon {
  width: 40px;
  text-align: center;
  margin: 0 50px;
  font-size: 18px;
  color: #fff;
  cursor: pointer;
  display: flex;
}

.header .menu-icon,
.header .cancel-icon {
  display: none;
}
.header .cart {
  color: #fff;
  cursor: pointer;
}
@media (max-width: 1245px) {
  .header {
    padding: 0 50px;
  }
}

@media (max-width: 1140px) {
  .header {
    padding: 0;
  }

  .header .logo {
    flex: 2;
    text-align: center;
  }

  .header .nav-items {
    position: fixed;
    z-index: 99;
    top: 150px;
    left: -100%;
    height: 900px;
    padding: 10px 50px 0 50px;
    text-align: center;
    background: #14181f;
    display: inline-block;
    transition: left 0.3s ease;
  }

  .header .nav-items.active {
    left: 0;
  }

  .header .nav-items li {
    line-height: 40px;
    margin: 30px 0;
    font-size: 20px;
  }
  .header .menu-icon {
    display: block;
  }
  .header .menu-icon span {
    display: block;
  }

  .header .menu-icon span.hide {
    display: none;
  }

  .header .cancel-icon.show {
    display: block;
  }
}

@media (max-width: 980px) {
  .header .menu-icon,
  .header .cancel-icon {
    margin: 0 20px;
  }

  .header form {
    right: 30px;
  }
}

@media (max-width: 350px) {
  .header .menu-icon,
  .header .cancel-icon {
    margin: 0 10px;
    font-size: 20px;
  }
}
</style>
